<template>
<view>
<!--pages/index/listQuery/list/list.wxml-->
<view v-for="(item, index) in nameList" :key="index" class="list-box" @tap="bindList" :data-id="item.model_id" :data-name="item.name">
  <view class="list-text">{{item.name}}</view>
  <image class="list-img" src="/static/images/sys/listel.png" v-if="item.isClick"></image>
</view>
</view>
</template>

<script>
// pages/index/listQuery/list/list.js
const util = require("../../../../utils/util.js");
const app = getApp();
let toggleCollection = true;

export default {
  data() {
    return {
      nameList: [],
      scroll: false,
      cityName: ''
    };
  },

  components: {},
  props: {},
  onLoad: function (options) {
    // util.colleation(this, "名单查询");
    toggleCollection = true;
    util.getUrl(app.globalData.url).then(res => {
      let $getResult = {
        ac: 'type',
        citycode: options.citycode
      };
      util.bstrequest('listQuery.php', $getResult, 'POST').then(res => {
        let nameList = JSON.parse(JSON.stringify(res.data.type));
        nameList.forEach((item, index) => {
          if (item.name == options.list_name) item.isClick = true;else item.isClick = false;
        });
        this.setData({
          nameList,
          cityName: options.cityName
        });
      });
    });
  },
  methods: {
    bindList: function (e) {
      let modelId = e.currentTarget.dataset.id;
      let listName = e.currentTarget.dataset.name;

      if (modelId == 1) {
        uni.navigateTo({
          url: `/pages/tools/yaohaojieguo/yaohaojieguo?city=${this.cityName}`
        });
        return;
      }

      this.nameList.forEach((item, index) => {
        if (item.id == modelId) item.isClick = true;else item.isClick = false;
      });
      this.setData({
        nameList: this.nameList
      });
      uni.redirectTo({
        url: `/pages/tools/listQuery/index/index?modelId=${modelId}&citycode=${this.citycode}&cityName=${this.cityName}`
      });
    },

    onPageScroll() {
      if (toggleCollection) {
        this.setData({
          scroll: true
        });
        toggleCollection = false;
      }
    },

    closeCollection() {
      toggleCollection = false;
    },

    openCollection() {
      toggleCollection = true;
    }

  }
};
</script>
<style>
/* pages/index/listQuery/list/list.wxss */
page {
    background-color: #F9F9F9;
  }
  
  .list-box{
    background-color: #ffffff;padding: 30rpx 40rpx;border-bottom: 1rpx solid #F5f5f5;
    display: flex;flex-direction: row;align-items: center;justify-content: space-between;
  }
  
  .list-text{font-size:28rpx;font-family:PingFang SC;font-weight:500;color:rgba(0,0,0,1);opacity:1;}
  .list-img{width: 40rpx;height: 29rpx;}
  
  
  
</style>